<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head th:include="include/head">
</head>
<body class="hold-transition sidebar-mini layout-fixed">
<div class="wrapper">
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1>专业列表</h1>
                    </div>
                    <div class="col-sm-6">
                        <ol class="breadcrumb float-sm-right">
                            <li class="breadcrumb-item"><a href="#">首页</a></li>
                            <li class="breadcrumb-item active">专业管理</li>
                        </ol>
                    </div>
                </div>
            </div>
            <!-- /.container-fluid -->
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-header">
                                <h3 class="card-title">专业列表</h3>
                                <button type="button" class="btn btn-primary btn-sm" id="add" style="float: right">新增</button>
                            </div>
                            <div class="card-header">
                                <form id="search-form2" class="navbar-form form-inline"  th:action="@{/major/majorList}" method="post">

                                    <div class="form-group " >
                                        <label>名称:</label>
                                        <div class="col-sm-4" >
                                            <input type="text" name="name" th:value="${name}" placeholder="专业名称" class="form-control">
                                        </div>
                                    </div>
                                    <div class="form-group " >
                                        <label>专业层次:</label>
                                        <div class="col-sm-4" >
                                            <select class="form-control" id="majorType" name="majorType" aria-required="true">
                                                <option value="">全部</option>
                                                <option value="4" th:selected="${majorType}==4">专科</option>
                                                <option value="1" th:selected="${majorType}==1">本科</option>
                                                <option value="2" th:selected="${majorType}==2">硕士</option>
                                                <option value="3" th:selected="${majorType}==3">博士</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group " >

                                        <button type="button" id="serch"  style="font-size:0.5rem;" class="btn btn-primary pull-right">查询</button>
                                    </div>
                                </form>
                            </div>
                            <div class="card-body">
                                <table class="table table-bordered">
                                    <thead>
                                    <tr>
                                        <th style="width: 30px">编号</th>
                                        <th style="width: 150px">专业名</th>
                                        <th>编码</th>
<!--                                        <th>排序</th>-->
                                        <th>专业层次</th>
                                        <th>状态</th>
                                        <th style="width: 160px">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr th:each="bean : ${pageInfo.list}" th:attr="id=tr_+${bean.majorId}">
                                        <td th:text="${beanStat.count}"></td><!--beanStat.count从1、2、3计数-->
                                        <td th:text="${bean.majorName}"></td>
<!--                                        <td th:text="${bean.majorDesc}"></td>-->
                                        <td th:text="${bean.back5}"></td>
                                        <td th:switch="${bean.majorType}">
                                            <span  th:case="1">本科</span>
                                            <span  th:case="2">硕士</span>
                                            <span  th:case="3">博士</span>
                                            <span  th:case="4">专科</span>
                                        </td>

                                        <td th:text="${bean.majorState==0?'禁用':'启用'}"></td>

                                        <!--<td th:text="${bean.getMajorType()}"></td>-->
<!--                                        <td th:text="${bean.state}==1?'启用':'禁用'"></td>-->
                                        <td>
                                            <a class="btn btn-info btn-sm edit" th:href="'majorDetail?MajorId='+${bean.majorId}">
                                                <i class="fas fa-pencil-alt"></i>编辑
                                            </a>
                                            <a href="javascript:;" th:attr="data-id=|${bean.majorId}" class="btn btn-danger btn-sm del">
                                                <i class="fas fa-trash"></i>删除
                                            </a>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                            <!-- /.card-body -->
                            <cms:page></cms:page>
                            <!-- /.card -->
                        </div>

                    </div>
                </div>
            </div>
        </section>
    </div>
</div>
    <!-- ./wrapper -->
    <div th:include="include/foot"></div>
    <script>
        $("#serch").click(function() {
            $("#search-form2").submit();
        });
        $().ready(function() {
            $("#add").click(function() {
                loadPage();
                location.href = 'majorDetail';
            });
            $(".edit").click(function() {
                loadPage();

            });
            $("#query").click(function() {
                var majorName= document.getElementById('majorName').value;
                location.href = 'getMajorListByNameSearch?majorName='+majorName;

            });
            $(".del").click(function() {
                if (confirm('确定删除这个专业吗？')) {
                    let id = $(this).data('id');
                    $.ajax({
                        url : 'deleteMajorById?MajorId=' + id,
                        success : function(e) {
                            $("#tr_" + id).remove();
                            layer.msg('删除成功', {icon: 1})
                            // if (e.res) {
                            //     alert("成功");
                            //     $("#tr_" + id).remove();
                            //     layer.msg('删除成功', {icon: 1})
                            // }
                        },error:function(e){
                            layer.msg(e.responseText, {icon: 5});
                        }
                    });
                }
            });
        });
        loadPage=function(){
            window.parent.loadPage();
        }
    </script>
</body>
</html>
